<!-- 以下代码为代码生成器生成，生成时间: 2018-03-19 22:26:09，作者：billjiang/475572229@qq.com-->
<section class="content-header">
    <h1>
        流程节点管理
        <small>列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="${basePath}"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">生产管理</a></li>
        <li class="active">流程节点管理</li>
    </ol>
</section>

<section class="content">
    <div class="row">
    
    	<div class="col-md-2">

            <!-- Profile Image -->
            <div class="box box-primary">
                <div class="box-body box-profile">
                    <div id="tree"></div>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
    
        <div class="col-md-10">
            <div class="box">
                <!-- /.box-header -->
                <div class="dataTables_filter" id="searchDiv" style="display: none">
                    <!--查询条件-->
                    <input type="search" placeholder="请输入流程名称" title="流程名称" name="name"
                                           class="form-control" id="name" operator="like" likeOption="true">
                    <input type="search" placeholder="请输入流程编码" title="流程编码" name="code"
                                           class="form-control" id="code" operator="like" likeOption="true">
                    <div class="btn-group">
                        <button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
                        <button type="button" class="btn btn-default" data-btn-type="reset">重置</button>
                    </div>
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" data-btn-type="add">新增</button>
                        <button type="button" class="btn btn-default" data-btn-type="edit">编辑</button>
                        <button type="button" class="btn btn-default" data-btn-type="delete">删除</button>
                    </div>
                </div>
                <div class="box-body">
                    <table id="pnode_table" class="table table-bordered table-striped table-hover">
                    </table>
                </div>
            </div>
        </div>
        
    </div>
</section>

<script>
    var pnodeTable, winId = "pnodeWin";
    
    
    var pnodeObject = {
			loadData: function (){
				var pnode_config = {
						//定义选中行事件
						rowClick : function(row, isSelected) {
							//sensorTable.reloadData();
						},
						//数据加载后，默认选中第一行
						loadComplete : function() {
							pnodeTable.selectFirstRow(true);
						}
					}
				
				pnodeTable = new CommonTable("pnode_table", "pnode", "searchDiv", pnode_config);
				//初始化菜单树
				this.initTree(0);
				//sensorTable.reloadData();
			},
			
			initTree: function (selectNodeId) {
	            var self = this;
	            var treeData = null;
	            ajaxPost(basePath + "/pflow/treeData", null, function (data) {
	                treeData = data;
	            });
	            $("#tree").treeview({
	                data: treeData,
	                showBorder: true,
	                expandIcon: "glyphicon glyphicon-stop",
	                collapseIcon: "glyphicon glyphicon-unchecked",
	                levels: 1,
	                onNodeSelected: function (event, data) {
	                	console.info(data);
	                	//$("#levelCode").val(data.levelCode);
	                	pnodeTable.reloadData();
	                }
	            });
	            if (treeData.length == 0)
	                return;
	            //默认选中第一个节点
	            selectNodeId = selectNodeId || 0;
	            $("#tree").data('treeview').selectNode(selectNodeId);
	            $("#tree").data('treeview').expandNode(selectNodeId);
	            $("#tree").data('treeview').revealNode(selectNodeId);
	        }
	}
    
    
    
    
    
    
    
    $(function (){
    	
    	pnodeObject.loadData();
    	
        //绑定按钮事件
        $("button[data-btn-type]").click(function () {
            var action = $(this).data("btn-type");
            var rowId = pnodeTable.getSelectedRowId();
            switch (action) {
                case "add":
                    modals.openWin({
                        winId: winId,
                        title: '新增流程节点',
                        width: "900px",
                        url: basePath + "/pnode/edit"
                    })
                    break;
                case "edit":
                    if (!rowId) {
                        modals.info('请选择要编辑的行');
                        return false;
                    }
                    modals.openWin({
                        winId: winId,
                        title: '编辑流程节点【' + pnodeTable.getSelectedRowData().name + '】',
                        width: '900px',
                        url: basePath + "/pnode/edit?id=" + rowId
                    });
                    break;
                case 'delete':
                    if (!rowId) {
                        modals.info('请选择要删除的行');
                        return false;
                    }
                    modals.confirm("是否要删除该行数据？", function () {
                        ajaxPost(basePath + "/pnode/delete/" + rowId, null, function (data) {
                            if (data.success) {
                                pnodeTable.reloadRowData();
                            } else {
                                modals.info("流程节点数据被引用，不可删除！");
                            }
                        });
                    })
                    break;
            }
        })
    })
</script>